package Files;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *
 * @author Huchnet
 */
public class WifiReader {

    File file = null;
    FileInputStream fis = null;
    BufferedInputStream bis = null;
    String lastLine=null;
    //DataInputStream dis = null;

    BufferedReader d=null;
    public WifiReader(String aFile){

        try {
            file= new File(aFile);
            fis = new FileInputStream(file);
            bis = new BufferedInputStream(fis);
            //dis = new DataInputStream(bis);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        d= new BufferedReader(new InputStreamReader(bis));
        d.markSupported();
    }
    public String getNextStream() throws IOException{
        return d.readLine();
    }
    public Estructura getNextObject() throws IOException{
        Estructura aEstructura = new Estructura();
        String data= null;
        boolean start=false;
        if(lastLine!=null && lastLine.contains("No.")){
            aEstructura.addStream(lastLine+"\n");
            start=true;
        }
        for(int i=0;i<50;i++){
            data=d.readLine();
            if(data.contains("No.") && start==false){
                aEstructura.addStream(data+"\n");
                start=true;
            }else if(data.contains("No.") && start==true){
                lastLine=data;
                break;
            }else{
                aEstructura.addStream(data+"\n");
            }
        }
        return aEstructura;
    }
    public void close(){
        try {
            fis.close();
            bis.close();
            //dis.close();
            d.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }

    }
}
